/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Author:
 *     coolair.loveU2@gmail.com
 *******************************************************************************/

package org.skyfree.ghyll.tcard.core.internal;

import java.io.File;

import org.apache.log4j.Logger;
import org.skyfree.ghyll.tcard.core.IStoragePath;
import org.skyfree.ghyll.tcard.core.ITResource;
import org.skyfree.ghyll.tcard.core.TCardCore;
import org.skyfree.ghyll.tcard.core.storage.ITCardStorageProvider;

/**
 * This class ...
 */

public abstract class AbstractTResource implements ITResource
{
	//private ILog log = Platform.getLog(Platform.getBundle(TCardCore.PLUGIN_ID));
	private Logger log = TCardCore.getLogManager().getLogger(this.getClass().getSimpleName());
	
	protected boolean loaded = false;
	protected boolean dirty = false;
	/**
	 * Each TResource Object has path
	 */
	IStoragePath path;
	
	/**
	 * Each TResource has the storage provider handle.
	 */
	ITCardStorageProvider provider = TCardStorage.getProvider();
	
	/**
	 * THe path can be set only when construction.
	 * @param path
	 */
	public AbstractTResource(IStoragePath path)
	{
		this.path = path;
	}
	
	@Override
	public IStoragePath getPath()
	{
		return this.path;
	}
	
	public void log(Exception e)
	{
		log.error(e.getMessage(),e.fillInStackTrace());
	}

	@Override
	public boolean isLoaded()
	{
		return this.loaded;
	}
	
	protected void setLoaded(boolean loaded)
	{
		this.loaded = loaded;
	}
	
	public void setPath(IStoragePath path)
	{
		this.path = path;
	}
	
	@Override
	public File getURI() 
	{
		File rootDir = new File(this.provider.getRootURL());
		return new File(rootDir,this.path.getPath().toString());
	}
}
